package com.ruoyi.web.controller.combat;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.combat.domain.CombatMethod;
import com.ruoyi.combat.service.ICombatMethodService;
import com.ruoyi.combat.util.weibo.WeiboApi;
import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课题算法管理Controller
 *
 * @author ruoyi
 * @date 2025-01-09
 */
@Api(tags = "公共服务：算法信息管理")
@RestController
@RequestMapping("/combat/method")
public class CombatMethodController extends BaseController {

    @Autowired
    private ICombatMethodService combatMethodService;

    @Autowired
    private WeiboApi weiboApi;

    /**
     * 查询课题算法管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:method:list')")
    @ApiOperation(value = "查询课题算法管理列表")
    @GetMapping("/list")
    public TableDataInfo list(CombatMethod combatMethod) {
        startPage();
        List<CombatMethod> list = combatMethodService.selectCombatMethodList(combatMethod);
        return getDataTable(list);
    }

    /**
     * 导出课题算法管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:method:export')")
    @Log(title = "课题算法管理", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "导出课题算法管理列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, CombatMethod combatMethod) {
        List<CombatMethod> list = combatMethodService.selectCombatMethodList(combatMethod);
        ExcelUtil<CombatMethod> util = new ExcelUtil<CombatMethod>(CombatMethod.class);
        util.exportExcel(response, list, "课题算法管理数据");
    }

    /**
     * 获取课题算法管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:method:query')")
    @ApiOperation(value = "获取课题算法管理详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(combatMethodService.selectCombatMethodById(id));
    }

    /**
     * 新增课题算法管理
     */
    @PreAuthorize("@ss.hasPermi('system:method:add')")
    @Log(title = "课题算法管理", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增课题算法管理")
    @PostMapping
    public AjaxResult add(@RequestBody CombatMethod combatMethod) {
        combatMethod.setCreateBy(getUsername());
        return toAjax(combatMethodService.insertCombatMethod(combatMethod));
    }

    /**
     * 修改课题算法管理
     */
    @PreAuthorize("@ss.hasPermi('system:method:edit')")
    @Log(title = "课题算法管理", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改课题算法管理")
    @PutMapping
    public AjaxResult edit(@RequestBody CombatMethod combatMethod) {
        combatMethod.setUpdateBy(getUsername());
        return toAjax(combatMethodService.updateCombatMethod(combatMethod));
    }

    /**
     * 删除课题算法管理
     */
    @PreAuthorize("@ss.hasPermi('system:method:remove')")
    @Log(title = "课题算法管理", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除课题算法管理")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(combatMethodService.deleteCombatMethodByIds(ids));
    }

    /**
     * 获取课题算法管理详细信息
     */
    @Anonymous
    @ApiOperation(value = "测试课题算法")
    @GetMapping(value = "test/{id}")
    public AjaxResult test(@PathVariable("id") Long id) {
        return success(combatMethodService.testCombatMethodById(id));
    }
    @Anonymous
    @ApiOperation(value = "获取微博token")
    @GetMapping(value = "getToken")
    public AjaxResult getToken() {
        return AjaxResult.success("scucess",weiboApi.getAccessToken());
    }

    @ApiOperation(value = "请求测试")
    @PostMapping(value = "test")
    public AjaxResult test(@RequestBody CombatMethod combatMethod) {
        String result = combatMethodService.testCombatMethod(combatMethod);
        return AjaxResult.success("scucess",result);
    }
}
